import React from 'react'
import { Routes, Route, Navigate } from 'react-router-dom'
import NotFound from '@p/NotFound'
import Login from '@p/Login'
import Layout from '@/Layout'
import routes from './routes'
import { isLogin } from '@u'
export default function AuthRoutes() {

  return (
    <Routes>
      <Route path="/" element={
        isLogin()
          ?
          <Layout />
          :
          <Navigate to='/login' />
      }>
        {
          routes.map(route => {
            return (
              <Route key={route.path} path={route.path} element={<route.element />} />
            )
          })
        }
        <Route path='/' element={<Navigate to='/dashBoard' replace />} />
      </Route>
      <Route path="/login" element={<Login />} />
      <Route path="*" element={<NotFound />} />
    </Routes>
  )
}
